﻿MPT.addAction("header", function(_elm) {

    var mail_jQ = $('.e_mail', _elm);
    var name_jQ = $('.e_name', _elm);
    var search_txt_jQ = $('.e_search_txt', _elm);
    var search_btn_jQ = $('.e_search_btn', _elm);
    var search_list_jQ = $('.e_search_list', _elm);
    var search_box_jQ = $('.e_search_box', _elm);
    var more_jQ = $('.e_more', _elm);

    //“我的好友”下拉框
    $('.e_fbox', _elm).hover(function() {
        $(this).addClass('active');
        $(this).find('div').removeClass('hide');
    },
	  function() {
	      $(this).removeClass('active');
	      $(this).find('div').addClass('hide');
	  });

    //用户昵称下拉框
    $('.e_nbox', _elm).hover(function() {
        $(this).addClass('active');
        $(this).find('.name').addClass('name_on')
        $(this).find('div').removeClass('hide');
    },
      function() {
          $(this).removeClass('active');
          $(this).find('.name').removeClass('name_on')
          $(this).find('div').addClass('hide');
      });

    //登陆状态下

    if (MPT.Config["session"]['userid'] != '') {

        $('.e_log_on', _elm).show();
        $('.e_log_off', _elm).hide();

        var nickname = MPT.Config["session"]['nickname'];
        name_jQ.html(nickname).attr('title', nickname);

        $.ajax({
            type: "GET",
            url: MPT.Config["interface"]["getSysMsgCount"],
            dataType: "json",
            success: function(_resp) {

                if (Backend.dataValidate(_resp)) {
                    mail_jQ.find('a').html(_resp.data);
                } else {
                    mail_jQ.find('a').html(0);
                }
            },
            error: function() {
                Debug.info('[action top_nav] 获得礼品数量并提示错误');
            }
        });

    } else {

        $('.e_log_on', _elm).hide();
        $('.e_log_off', _elm).show();
    };

    var documentClick = function() {
        search_list_jQ.hide();
        $(this).unbind('click', documentClick);
    };

    //搜索框
    search_txt_jQ.focus(function() {
        if (this.value != '找人' && this.value != '') {
            search_list_jQ.show();
        }
        if (this.value == '找人') {
            this.value = '';
        }
        search_txt_jQ.keyup(function() {
            if (this.value.length > 0) {
                search_list_jQ.show();
            } else {
                search_list_jQ.hide()
            }

            more_jQ.unbind('click').click(function(e) {
                window.location.hash = MPT.Config["hash"]["find"] + '/' + search_txt_jQ.val();
            });
        })

        $(document).not(search_box_jQ.get()).bind('click', documentClick);

        //阻止冒泡
        search_box_jQ.click(function(e) {
            e.stopPropagation();
        });

    }).blur(function() {
        if (this.value == '') {
            this.value = '找人';
        }
    });


});
